/*  Not implemented yet.  The first focus is getting the UI in shape.

//loads argument map from database
var db = null;
try {
    if (window.openDatabase) {
        db = openDatabase("NodeTest", "1.0", "HTML5 Database API example", 200000);
        if (!db)
            alert("Failed to open the database on disk.  This is probably because the version was bad or there is not enough space left in this domain's quota");
    } else
        alert("Couldn't open the database.  Please try with a WebKit nightly with this feature enabled");
} catch(err) {
    db = null;
    alert("Couldn't open the database.  Please try with a WebKit nightly with this feature enabled");
}
//end section

Node.prototype.saveSoon = function()
    {
        this.cancelPendingSave();
        var self = this;
        this._saveTimer = setTimeout(function() { self.save() }, 200);
    }

Node.prototype.cancelPendingSave = function()
    {
        if (!("_saveTimer" in this))
            return;
        clearTimeout(this._saveTimer);
        delete this._saveTimer;
    }

Node.prototype.save = function()
    {
        this.cancelPendingSave();

        if ("dirty" in this) {
            this.timestamp = new Date().getTime();
            delete this.dirty;
        }

        var displayedDiv = this;
        db.transaction(function (tx)
        {
            tx.executeSql("UPDATE WebKitStickyNotes SET node = ?, timestamp = ?, left = ?, top = ?, zindex = ? WHERE id = ?", [displayedDiv.text, displayedDiv.timestamp, displayedDiv.left, displayedDiv.top, displayedDiv.zIndex, displayedDiv.id]);
        });
    }

Node.prototype.saveAsNew = function()
    {
        this.timestamp = new Date().getTime();
        
        var displayedDiv = this;
        db.transaction(function (tx) 
        {
            tx.executeSql("INSERT INTO WebKitStickyNotes (id, node, timestamp, left, top, zindex) VALUES (?, ?, ?, ?, ?, ?)", [displayedDiv.id, displayedDiv.text, displayedDiv.timestamp, displayedDiv.left, displayedDiv.top, displayedDiv.zIndex]);
        }); 
    }

//load argument map from SQL database
function loaded()
{
    db.transaction(function(tx) {
        tx.executeSql("SELECT COUNT(*) FROM WebkitStickyNotes", [], function(result) {
            loadNodes();
        }, function(tx, error) {
            tx.executeSql("CREATE TABLE WebKitStickyNotes (id REAL UNIQUE, node TEXT, timestamp REAL, left TEXT, top TEXT, zindex REAL)", [], function(result) { 
                loadNodes(); 
            });
        });
    });
}

//create Nodes based on data from SQL database
function loadNodes()
{
    db.transaction(function(tx) {
        tx.executeSql("SELECT id, node, timestamp, left, top, zindex FROM WebKitStickyNotes", [], function(tx, result) {
            for (var i = 0; i < result.rows.length; ++i) {
                var row = result.rows.item(i);
                var Node = new Node();
                Node.id = row['id'];
                Node.text = row['node'];
                Node.timestamp = row['timestamp'];
                Node.left = row['left'];
                Node.top = row['top'];
                Node.zIndex = row['zindex'];

                if (row['id'] > highestId)
                    highestId = row['id'];
                if (row['zindex'] > highestZ)
                    highestZ = row['zindex'];
            }

            if (!result.rows.length)
                newNode();
        }, function(tx, error) {
            alert('Failed to retrieve notes from database - ' + error.message);
            return;
        });
    });
}

//used for timestamp
function modifiedString(date)
{
    return 'Last Modified: ' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
}

/*if (db != null)
    addEventListener('load', loaded, false);*/
